﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Documents;
using BGM.Core.DAL;
using BGM.Domain.DTO;


namespace BloodGlucoseManagerApplication
{
  public  class Controller
    {
        PerisitenceManager dm;
        private Patient selectedPatient;

        public Patient SelectedPatient
        {
            get { return selectedPatient; }
            set { selectedPatient = value; }
        }
        public Controller()
        {
            dm =  new PerisitenceManager();
           // List<KeyValuePair<string, string>> p = dm.GetPatients();
           // dm.SaveReadings("10101010", CreateTestData());
         // List<Reading> list =  dm.GetReadings("10101010", DateTime.Now, DateTime.Now);
        }

        public void SaveReadings(List<Reading> list)
        {
            if(selectedPatient!=null)
            dm.SaveReadings(selectedPatient.Ssn, list);

        }
        public List<Reading> GetReadings(DateTime from, DateTime to, bool onlyWorkingDays)
        {
            return dm.GetReadings(selectedPatient.Ssn, from, to,onlyWorkingDays);
        }
        public List<Patient> GetAllPatients()
        {
            return dm.GetPatients();
        }
       
        internal void Exit()
        {
            App.Current.Dispatcher.InvokeShutdown();
        }

        internal void LoadPatient(MainWindow mainWindow)
        {
            SelectPatientWindow selectPatient = new SelectPatientWindow(this);
            selectPatient.Owner = mainWindow;
            selectPatient.ShowDialog();
            if(this.SelectedPatient!=null)
            mainWindow.Title = "Blood Glucose Manager - Patient" + this.SelectedPatient.Ssn;
        }

        internal void ShowCreateNewPatient(MainWindow mainWindow)
        {
            CreateNewPatientWindow w = new CreateNewPatientWindow(this);
            w.Owner = mainWindow;
            w.ShowDialog();
        }

        internal void CreateNewPatient(string name, string ssn, DateTime morning, DateTime midtDay, DateTime dinner, DateTime neight, int low, int high)
        {
           dm.CreatePatient( name,  ssn,  morning,  midtDay,  dinner,  neight,  low,  high);
        }
    }
}
